<?php

namespace App\Http\Controllers\Admin;

use App\Http\Requests\CreateGoodsSlideshowRequest;
use App\Http\Requests\UpdateGoodsSlideshowRequest;
use App\Repositories\GoodsSlideshowRepository;
use App\Http\Controllers\AppBaseController;
use Illuminate\Http\Request;
use Flash;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;

class GoodsSlideshowController extends AppBaseController
{
    /** @var  GoodsSlideshowRepository */
    private $goodsSlideshowRepository;

    public function __construct(GoodsSlideshowRepository $goodsSlideshowRepo)
    {
        $this->goodsSlideshowRepository = $goodsSlideshowRepo;
    }

    /**
     * Display a listing of the GoodsSlideshow.
     *
     * @param Request $request
     * @return Response
     */
    public function index(Request $request)
    {
        $this->goodsSlideshowRepository->pushCriteria(new RequestCriteria($request));
        $goodsSlideshows = $this->goodsSlideshowRepository->paginate(10);

        return view('goods_slideshows.index')
            ->with('goodsSlideshows', $goodsSlideshows);
    }

    /**
     * Show the form for creating a new GoodsSlideshow.
     *
     * @return Response
     */
    public function create()
    {
        return view('goods_slideshows.create');
    }

    /**
     * Store a newly created GoodsSlideshow in storage.
     *
     * @param CreateGoodsSlideshowRequest $request
     *
     * @return Response
     */
    public function store(CreateGoodsSlideshowRequest $request)
    {
        $input = $request->all();

        $goodsSlideshow = $this->goodsSlideshowRepository->create($input);

        Flash::success('Goods Slideshow saved successfully.');

        return redirect(route('goodsSlideshows.index'));
    }

    /**
     * Display the specified GoodsSlideshow.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $goodsSlideshow = $this->goodsSlideshowRepository->findWithoutFail($id);

        if (empty($goodsSlideshow)) {
            Flash::error('Goods Slideshow not found');

            return redirect(route('goodsSlideshows.index'));
        }

        return view('goods_slideshows.show')->with('goodsSlideshow', $goodsSlideshow);
    }

    /**
     * Show the form for editing the specified GoodsSlideshow.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $goodsSlideshow = $this->goodsSlideshowRepository->findWithoutFail($id);

        if (empty($goodsSlideshow)) {
            Flash::error('Goods Slideshow not found');

            return redirect(route('goodsSlideshows.index'));
        }

        return view('goods_slideshows.edit')->with('goodsSlideshow', $goodsSlideshow);
    }

    /**
     * Update the specified GoodsSlideshow in storage.
     *
     * @param  int              $id
     * @param UpdateGoodsSlideshowRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateGoodsSlideshowRequest $request)
    {
        $goodsSlideshow = $this->goodsSlideshowRepository->findWithoutFail($id);

        if (empty($goodsSlideshow)) {
            Flash::error('Goods Slideshow not found');

            return redirect(route('goodsSlideshows.index'));
        }

        $goodsSlideshow = $this->goodsSlideshowRepository->update($request->all(), $id);

        Flash::success('Goods Slideshow updated successfully.');

        return redirect(route('goodsSlideshows.index'));
    }

    /**
     * Remove the specified GoodsSlideshow from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $goodsSlideshow = $this->goodsSlideshowRepository->findWithoutFail($id);

        if (empty($goodsSlideshow)) {
            Flash::error('Goods Slideshow not found');

            return redirect(route('goodsSlideshows.index'));
        }

        $this->goodsSlideshowRepository->delete($id);

        Flash::success('Goods Slideshow deleted successfully.');

        return redirect(route('goodsSlideshows.index'));
    }
}
